define(function(require,exports,modlue){
	
	//排序
	$(".bondList li").click(function(){
		var $this = $(this),
		      $a = $this.find("a"),
		      $i = $this.find("i"),
		      val = $a .attr("data-val"),
		      param = "";
		if($this.hasClass("current"))
		{
			if(val == "desc")
			{
				$a.attr("data-val","asc");
				$i .removeClass("desc").addClass("asc");
			}
			else if(val == "asc")
			{
				$a.attr("data-val","desc");
				$i .removeClass("asc").addClass("desc");
			}
		}
		else
		{
			$this.addClass("current").siblings().removeClass("current");
		}
		if(val == "normal")
		{
			param = "/bond/bondList.html?sign=1";
		}
		else
		{
			param = "/bond/bondList.html?sort="+$a.attr("data-type")+"&order="+$a.attr("data-val");
		}
		ajaxUrl(param);
	});

	ajaxUrl('/bond/bondList.html?sign=1' + '&randomTime' + (new Date()).getTime());
	//通用显示函数
	function ajaxUrl(param){
		$.ajax({
			type:'get',
			cache:false,
			url:param + "&randomTime=" + (new Date()).getTime(),
			dataType:'json',
			success:function(json){
				//总记录数				
				var tpl = require('../../tpl/bond/index.tpl');
				var template = Handlebars.compile(tpl);
				var html = template(json);
				$('.bondtListBox').html(html);
					
			
				//分页插件
				if(json.data.page.pages > 0)
				{
					require.async(['/plugins/pager/pager.css','/plugins/pager/pager'],function(){
						kkpager.generPageHtml({
							pno : json.data.page.currentPage,//当前页码
							total : json.data.page.pages,//总页码
							totalRecords : json.data.page.total,//总数据条数
							isShowFirstPageBtn	: false, 
							isShowLastPageBtn	: false, 
							isShowTotalPage 	: false, 
							isShowTotalRecords 	: false, 
							isGoPage 			: false,
							lang:{
								prePageText				: '<',
								nextPageText			: '>'
							},
							mode:'click',//click模式匹配getHref 和 click
							click:function(n,total,totalRecords){
					        	$.ajax({
					        		type:"get",
					        		cache:false,
					        		url:param + "&page=" + n + "&randomTime=" + (new Date()).getTime(),
					        		dataType:"json",//这个必不可少，如果缺少，导致传回来的不是json格式
					        		success:function(json){
										var tpl = require('../../tpl/bond/index.tpl');
										var template = Handlebars.compile(tpl);
										var html    = template(json);
										$('.bondtListBox').html(html);
					        		}
					        	});
								this.selectPage(n); //处理完后可以手动条用selectPage进行页码选中切换
							}
						});
					});
				}else{
					$("#kkpager").html('暂无数据');
				}
			}
		});	
	}
	//最新转让成交记录
	$.ajax({
		url:"/bond/latestTenerList.html?randomTime=" + (new Date()).getTime(),
		type:"get",
		dataType:"json",
		cache:false,
		success:function(json){
			$(".bondRecord ul").html(Handlebars.compile(require('../../tpl/bond/latestTenerList.tpl'))(json));
		}
	});
	//翻页置顶
	require.async("commonJS/rollTo",function(){
		$("#kkpager").rollTo({
			oFinish: ".bondList", //要滚动到的元素
			sSpeed: "300",  //滚动速度
			bMonitor: false, //是否楼层监听
			sClass: "", //楼层监听时需要添加的样式
			iBias:-18,
			fnAdditional: "" //追加方法
		});
	});
});